#include "projectmodel.h"
#include "QtCore/qvariant.h"

ProjectModel::ProjectModel(ProjectModel * parent) {
    // m_root = new ProjectModel();
    // m_root->title = "root";
    m_childItems =  QVector<ProjectModel*>();
    m_parent = parent;
}



//子节点数量
int ProjectModel::subsCount() const {
    return int(m_childItems.size());
}


void ProjectModel::addSub(ProjectModel * sub) {
    m_childItems.append(sub);
}

void ProjectModel::addSub2(std::unique_ptr<ProjectModel> && sub) {
        m_childItems2.push_back(std::move(sub));
}

ProjectModel * ProjectModel::parent() {
    return m_parent;
}


ProjectModel * ProjectModel::getSub(int column) const
{
    if (column < 0 || column >= m_childItems.size())
        return nullptr;
    ProjectModel * m = m_childItems.at(column);
    return m;
}

QVariant ProjectModel::getSub2(int column) const
{
    if (column < 0 || column >= m_childItems.size())
        return QVariant();
    ProjectModel * m = m_childItems.at(column);
    QVariant variant = QVariant::fromValue(m);
    return variant;
}

bool ProjectModel::setData(int column, const QVariant &value)
{
    if (column < 0 || column >= m_childItems.size())
        return false;
    ProjectModel * m = value.value<ProjectModel *>();
    m_childItems[column] = m;
    return true;
}



